import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('backGround')
export class backGround extends Component {
    @property(Node)
    bg1: Node = null;
    @property(Node)
    bg2: Node = null;
    private speed = 10;
    private moveRange = 90;
    start() {
        this._initBackGround();
    }

    update(deltaTime: number) {
        this.moveBackgound(deltaTime);
    }
    private moveBackgound(deltaTime: number) {
        this.bg1.setPosition(0, 0, this.bg1.position.z + this.speed * deltaTime);
        this.bg2.setPosition(0, 0, this.bg2.position.z + this.speed * deltaTime);
        if (this.bg1.position.z > 90) {
            this.bg1.setPosition(0, 0, this.bg2.position.z - 90);
        }
        else if (this.bg2.position.z > 90) {
            this.bg2.setPosition(0, 0, this.bg1.position.z - 90);
        }
    }

    private _initBackGround() {
        this.bg1.setPosition(0, 0, 0);
        this.bg2.setPosition(0, 0, -90);
    }
}

